package com.gmall.product.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gmall.common.result.Result;
import com.gmall.model.product.BaseTrademark;
import com.gmall.product.mapper.BaseTrademarkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class BaseTrademarkService {

    @Autowired
    BaseTrademarkMapper baseTrademarkMapper;
    public Result<Page<BaseTrademark>> findPage(Integer page, Integer limit) {

        Page<BaseTrademark> pageInfo = new Page<>(page, limit);
        baseTrademarkMapper.selectPage(pageInfo, Wrappers.emptyWrapper());
        return Result.ok(pageInfo);
    }

    public Result<String> save(BaseTrademark baseTrademark) {
        Date now = new Date();
        baseTrademark.setCreateTime(now);
        baseTrademark.setUpdateTime(now);
        baseTrademarkMapper.insert(baseTrademark);

        return Result.ok();
    }

    public Result<String> remove(Long id) {
        baseTrademarkMapper.deleteById(id);
        return Result.ok();
    }

    public Result<String> update(BaseTrademark baseTrademark) {
        baseTrademark.setUpdateTime(new Date());
        baseTrademarkMapper.updateById(baseTrademark);
        return Result.ok();
    }

    public Result<BaseTrademark> getById(Long id) {
        BaseTrademark baseTrademark = baseTrademarkMapper.selectById(id);
        return Result.ok(baseTrademark);
    }
}
